import { apiAddNotice } from '../../api/index'

export const getRoute = function (page) {
  page['getRoute'] = function () {
    let routes = getCurrentPages()
    if (routes.length > 1) {
      return routes[routes.length - 2]
    } else {
      return null
    }
  }
}

export const submitFromData = function (page) {
  if (page.hasOwnProperty('methods')) {
    page['methods']['_submitFrom'] = function (id) {
      if (!id) {
        return
      }
      const PARAMS = {
        open_id: wx.getStorageSync('openid'),
        formId: id,
        loading: 1
      }
      apiAddNotice(PARAMS).then(res => {
      })
    }
  } else {
    page['_submitFrom'] = function (id) {
      if (!id) {
        return
      }
      const PARAMS = {
        open_id: wx.getStorageSync('openid'),
        formId: id,
        loading: 1
      }
      apiAddNotice(PARAMS).then(res => {
      })
    }
  }
}